﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;

namespace WcfCGServicesHost
{
    public class CallLoggingEndpointBehavior : IEndpointBehavior
    {
        #region Fields

        private CallLogger callLogger = null;

        #endregion

        #region Constructors

        public CallLoggingEndpointBehavior(CallLogger callLogger)
        {
            this.callLogger = callLogger;
        }

        #endregion

        #region IEndpointBehavior Members

        public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
        {
        }

        public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
        {
        }

        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
        {
            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(this.callLogger);
        }

        public void Validate(ServiceEndpoint endpoint)
        {
        }

        #endregion
    }
}
